package com.banciyuan.bcywebview.biz.write.photoselecotor.pselector;

import android.content.Context;
import android.os.AsyncTask;

import com.banciyuan.bcywebview.biz.write.photoselecotor.controller.AlbumController;
import com.banciyuan.bcywebview.biz.write.photoselecotor.model.AlbumModel;
import com.banciyuan.bcywebview.biz.write.photoselecotor.model.PhotoModel;

import java.util.List;

/**
 * Created by squall on 2017/3/16.
 */

public class PhotoHelper {

    private AlbumController albumController;

    public PhotoHelper(Context context) {
        albumController = new AlbumController(context);
    }

    public void getReccent(final PhotoListener photoListener) {
        new AsyncTask<Void, List<PhotoModel>, List<PhotoModel>>() {
            @Override
            protected List<PhotoModel> doInBackground(Void... params) {
                return albumController.getCurrent();
            }

            @Override
            protected void onPostExecute(List<PhotoModel> photoModels) {
                photoListener.onPhotoLoaded(photoModels);
            }
        }.execute();
    }

    /**
     * 获取相册列表
     */
    public void updateAlbum(final AlbumListener albumListener) {
        new AsyncTask<Void, List<AlbumModel>, List<AlbumModel>>() {
            @Override
            protected List<AlbumModel> doInBackground(Void... params) {
                return albumController.getAlbums();
            }

            @Override
            protected void onPostExecute(List<AlbumModel> albumModels) {
                albumListener.onAlbumLoaded(albumModels);
            }
        }.execute();
    }

    /**
     * 获取单个相册下的所有照片信息
     */
    public void getAlbum(final String name, final PhotoListener photoListener) {
        new AsyncTask<Void, List<PhotoModel>, List<PhotoModel>>() {
            @Override
            protected List<PhotoModel> doInBackground(Void... params) {
                return albumController.getAlbum(name);
            }

            @Override
            protected void onPostExecute(List<PhotoModel> photoModels) {
                photoListener.onPhotoLoaded(photoModels);
            }
        }.execute();
    }
}
